package com.wash.car.biz.impl;

import cn.hutool.core.util.ObjectUtil;
import com.wash.car.biz.UserServer;
import com.wash.car.dao.domain.AbBaseDomain;
import com.wash.car.dao.domain.CarUserDomain;
import com.wash.car.dao.mapper.CarUserMapper;
import com.wash.car.dao.model.UserAddModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class UserServerImpl implements UserServer {

    @Resource
    private CarUserMapper carUserMapper;

    @Override
    public CarUserDomain wxRegister(UserAddModel model) {
        CarUserDomain dbDomain = carUserMapper.selectOne(new CarUserDomain().setOpenid(model.getOpenid()));
        if (ObjectUtil.isEmpty(dbDomain)) {
            CarUserDomain addDomain = AbBaseDomain.setDefaultValue(CarUserDomain.class);
            addDomain.setOpenid(model.getOpenid());
            carUserMapper.insertSelective(addDomain);
            dbDomain = carUserMapper.selectByPrimaryKey(addDomain.getId());
        }
        return dbDomain;
    }
}
